#include<iostream>
using namespace std;
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>


int main(){
    //测试重定向
    close(1);
    umask(0);
    int fd = open("log.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
    if(fd < 0){
        perror("open");
        return 1;
    }
    fprintf(stdout,"fd:%d\n",fd);
    fflush(stdout);
    
    //printf("fd:%d\n",fd);
    close(fd);
    return 0;
}